$(document).ready(function (data) {
	checkScore();
});

function display (imageLink){
	$('.title').html('');
	$('#imgDisplay').attr('src',imageLink);
	$.post('display.php',{link:imageLink},function (data) {
		$('#panswer').html(data);
		if (!data) {
			var form = 'Answer: <input type="text" name="answer" /><input id="link" type="hidden" name="link" /><input id="submit" type="button" value="Submit" onclick="validate()" />';
			$('#fanswer').html(form);
			$('#link').attr('value',imageLink);
		}
		else {
			$('#fanswer').html('');
		}
	});
}

function validate () {
	$.post('answer.php',$('#fanswer').serialize(),function (data) {
		$('#panswer').html(data);
		checkScore();
	});
}

function checkScore () {
	$.post('score.php',function (data) {
		$('#score').html(data);
	});
}

function reset (){
	if (confirm('Reset game?')) {
		$.post('reset.php', function(data) {
			location.reload();
		});
	}
}

